#pragma once
#include"../../src_baseClasses/DataParser.h"
#include "Data_grid.h"
#include <vector>
#include <QString>

#include <QFile>
#include <QTextStream>

class DataParser_grid : public DataParser {
public:
	DataParser_grid(Data_grid* data) : m_data(data) {};

	//实例化基类虚函数
	bool readFile(const QString& qFullName);
	bool saveFile(const QString& qFullName);
	bool saveFileAs(const QString& qFullName);
	void setMinMax();

public:
	static std::vector<LineUI> getRandomPts(int width, int height, int randPtSum = 0);
	static void setPtsFromLines(std::vector<LineUI>& liness, std::vector<QPointF>& pts);		//设置线段上所有整数点
	static void setPtsFromLines(std::vector<std::vector<LineUI>>& liness, std::vector<std::vector<QPointF>>& pts);
	struct numbers { //用于读取数据
		double num1;
		double num2;
		double num3;
		double num4;
		double num5;

		double& operator[](int index) {
			switch (index) {
			case 0: return num1;
			case 1: return num2;
			case 2: return num3;
			case 3: return num4;
			case 4: return num5;
			default: throw std::out_of_range("Index out of range");
			}
		}
	};

	//3.文件输出
	static bool write_PPDT_case(const QString& qFullName, const Data_grid* data);
	static bool write_PPDT_Pre(const QString& qFullName, const std::vector<LineUI>& pinPairs, const std::vector<std::vector<QPointF>>& pathPts, const std::vector<QString>& mapSymbols);
	static bool write_PPDT_Res(const QString& qFullName, const std::vector<std::vector<QPointF>>& pathPts, const std::vector<QString>& mapSymbols);

private:
	Data_grid* m_data;
	bool read_text_to_map(const QString& qFullName);
	bool read_image_to_map(const QString& qFullName, const QString& qfielPath, const QString& qBaseName);
	bool read_map_routing_res(const QString& qFullName);
};